from fontTools.misc.cython import returns
from numpy.ma.extras import average

try:
    n = int(input())
    if n<=1 or n>=100:
        raise ValueError("输入的人数必须是数字,大于0并且小于等于100")

except ValueError as e:
    print(e)
    returns

student = []
for i in range(n):
    try:
        student_info = input().strip().split()
        if len(student_info)!=5:
            raise ValueError("每个学生的信息必须包含学号、姓名和3门课成绩")
        id = student_info[0]
        name = student_info[1]
        chinese = int(student_info[2])
        math = int(student_info[3])
        english = int(student_info[4])

        if not (id.isdigit() and len(id) == 4):
            raise ValueError("学号必须是4位数字")
        if chinese < 0 or math < 0 or english < 0:
            raise ValueError("成绩必须是正整数")

        average = (chinese+math+english)/3
        student.append((id,name,chinese,math,english,average))
    except ValueError as e:
        print(e)
        returns
student.sort(key=lambda x:(-x[5],-x[2]))

for i in student:
    print(f"{i[0]} {i[1]} {i[2]} {i[3]} {i[4]} {i[5]:.2f}")



